namespace QLGT.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class FirstMigration : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.sysdiagrams",
                c => new
                    {
                        diagram_id = c.Int(nullable: false, identity: true),
                        name = c.String(nullable: false, maxLength: 128),
                        principal_id = c.Int(nullable: false),
                        version = c.Int(),
                        definition = c.Binary(),
                    })
                .PrimaryKey(t => t.diagram_id);
            
            CreateTable(
                "dbo.tbl_ChucNang",
                c => new
                    {
                        MaCN = c.Int(nullable: false, identity: true),
                        TenCN = c.String(nullable: false, maxLength: 50),
                        Link = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(nullable: false, maxLength: 50),
                        MaCNCha = c.Int(nullable: false),
                        TrangThai = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaCN);
            
            CreateTable(
                "dbo.tbl_ChucNang_Quyen",
                c => new
                    {
                        MaQuyen = c.Int(nullable: false),
                        MaCN = c.Int(nullable: false),
                        TrangThai = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MaQuyen, t.MaCN })
                .ForeignKey("dbo.tbl_Quyen", t => t.MaQuyen)
                .ForeignKey("dbo.tbl_ChucNang", t => t.MaCN)
                .Index(t => t.MaQuyen)
                .Index(t => t.MaCN);
            
            CreateTable(
                "dbo.tbl_Quyen",
                c => new
                    {
                        MaQuyen = c.Int(nullable: false, identity: true),
                        Quyen = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaQuyen);
            
            CreateTable(
                "dbo.tbl_NguoiDung",
                c => new
                    {
                        TenDangNhap = c.String(nullable: false, maxLength: 20, fixedLength: true),
                        MaQuyen = c.Int(nullable: false),
                        MatKhau = c.String(nullable: false, maxLength: 20, fixedLength: true),
                        Email = c.String(nullable: false, maxLength: 50, fixedLength: true),
                        RandomPass = c.String(nullable: false, maxLength: 50, fixedLength: true),
                        KhoaTaiKhoan = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.TenDangNhap)
                .ForeignKey("dbo.tbl_Quyen", t => t.MaQuyen)
                .Index(t => t.MaQuyen);
            
            CreateTable(
                "dbo.tbl_ChucVu",
                c => new
                    {
                        MaChucVu = c.Int(nullable: false, identity: true),
                        ChucVu = c.String(nullable: false, maxLength: 50),
                        GhiChu = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaChucVu);
            
            CreateTable(
                "dbo.tbl_TacGia",
                c => new
                    {
                        MaTacGia = c.Int(nullable: false, identity: true),
                        TenTacGia = c.String(nullable: false, maxLength: 50),
                        MaHocHam = c.Int(),
                        MaHocVi = c.Int(),
                        MaChucVu = c.Int(),
                        GhiChu = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.MaTacGia)
                .ForeignKey("dbo.tbl_ChucVu", t => t.MaChucVu)
                .ForeignKey("dbo.tbl_HocHam", t => t.MaHocHam)
                .ForeignKey("dbo.tbl_HocVi", t => t.MaHocVi)
                .Index(t => t.MaHocHam)
                .Index(t => t.MaHocVi)
                .Index(t => t.MaChucVu);
            
            CreateTable(
                "dbo.tbl_GiaoTrinh",
                c => new
                    {
                        MaGiaoTrinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenGiaoTrinh = c.String(nullable: false, maxLength: 200),
                        MaTacGia = c.Int(nullable: false),
                        HieuDinh = c.DateTime(),
                        SoTrang = c.Int(nullable: false),
                        SoChuong = c.Int(nullable: false),
                        MaNXB = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaGiaoTrinh)
                .ForeignKey("dbo.tbl_NhaXuatBan", t => t.MaNXB)
                .ForeignKey("dbo.tbl_TacGia", t => t.MaTacGia)
                .Index(t => t.MaTacGia)
                .Index(t => t.MaNXB);
            
            CreateTable(
                "dbo.tbl_GiaoTrinh_HeDT",
                c => new
                    {
                        MaGT_HDT = c.Int(nullable: false, identity: true),
                        MaGiaoTrinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaHeDaoTao = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaGT_HDT)
                .ForeignKey("dbo.tbl_HeDaoTao", t => t.MaHeDaoTao)
                .ForeignKey("dbo.tbl_GiaoTrinh", t => t.MaGiaoTrinh)
                .Index(t => t.MaGiaoTrinh)
                .Index(t => t.MaHeDaoTao);
            
            CreateTable(
                "dbo.tbl_HeDaoTao",
                c => new
                    {
                        MaHeDaoTao = c.Int(nullable: false, identity: true),
                        TenHeDaoTao = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaHeDaoTao);
            
            CreateTable(
                "dbo.tbl_GiaoTrinh_Nam",
                c => new
                    {
                        MaGiaoTrinh_Nam = c.Int(nullable: false, identity: true),
                        MaGiaoTrinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaMonHoc = c.Int(nullable: false),
                        GiaNiemYet = c.Int(nullable: false),
                        Nam = c.String(nullable: false, maxLength: 4, fixedLength: true),
                        GhiChu = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.MaGiaoTrinh_Nam)
                .ForeignKey("dbo.tbl_GiaoTrinh", t => t.MaGiaoTrinh)
                .Index(t => t.MaGiaoTrinh);
            
            CreateTable(
                "dbo.tbl_MonHoc",
                c => new
                    {
                        MaMonHoc = c.Int(nullable: false),
                        TenMonHoc = c.String(nullable: false, maxLength: 100),
                        MaKhoa = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaGiaoTrinh = c.String(maxLength: 10, fixedLength: true),
                    })
                .PrimaryKey(t => t.MaMonHoc)
                .ForeignKey("dbo.tbl_GiaoTrinh", t => t.MaGiaoTrinh)
                .ForeignKey("dbo.tbl_Khoa", t => t.MaKhoa)
                .Index(t => t.MaKhoa)
                .Index(t => t.MaGiaoTrinh);
            
            CreateTable(
                "dbo.tbl_DaoTao",
                c => new
                    {
                        MaNganh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaMonHoc = c.Int(nullable: false),
                        NamHoc = c.Int(nullable: false),
                        KyHoc = c.Int(nullable: false),
                        SoTinChi = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MaNganh, t.MaMonHoc })
                .ForeignKey("dbo.tbl_Nganh", t => t.MaNganh)
                .ForeignKey("dbo.tbl_MonHoc", t => t.MaMonHoc)
                .Index(t => t.MaNganh)
                .Index(t => t.MaMonHoc);
            
            CreateTable(
                "dbo.tbl_Nganh",
                c => new
                    {
                        MaNganh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        Nganh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenNganh = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaNganh);
            
            CreateTable(
                "dbo.tbl_Khoa",
                c => new
                    {
                        MaKhoa = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        Khoa = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenKhoa = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaKhoa);
            
            CreateTable(
                "dbo.tbl_SachBan",
                c => new
                    {
                        MaSachBan = c.Int(nullable: false),
                        MaGiaoTrinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        SoLuong = c.Int(nullable: false),
                        NgayBan = c.DateTime(nullable: false),
                        MaKhoa = c.String(maxLength: 10, fixedLength: true),
                        SinhVien = c.Int(),
                    })
                .PrimaryKey(t => t.MaSachBan)
                .ForeignKey("dbo.tbl_Khoa", t => t.MaKhoa)
                .ForeignKey("dbo.tbl_GiaoTrinh", t => t.MaGiaoTrinh)
                .Index(t => t.MaGiaoTrinh)
                .Index(t => t.MaKhoa);
            
            CreateTable(
                "dbo.tbl_NhaXuatBan",
                c => new
                    {
                        MaNXB = c.Int(nullable: false),
                        TenNXB = c.String(nullable: false, maxLength: 100),
                        DiaChi = c.String(nullable: false, maxLength: 200),
                        SoDT = c.String(nullable: false, maxLength: 15, fixedLength: true),
                        Fax = c.String(nullable: false, maxLength: 15, fixedLength: true),
                        Email = c.String(nullable: false, maxLength: 50, fixedLength: true),
                    })
                .PrimaryKey(t => t.MaNXB);
            
            CreateTable(
                "dbo.tbl_SachDat",
                c => new
                    {
                        MaSachDat = c.Int(nullable: false),
                        MaGiaoTrinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        SoLuong = c.Int(nullable: false),
                        NgayDat = c.DateTime(nullable: false),
                        MaNXB = c.Int(nullable: false),
                        GhiChu = c.String(maxLength: 200),
                    })
                .PrimaryKey(t => t.MaSachDat)
                .ForeignKey("dbo.tbl_NhaXuatBan", t => t.MaNXB)
                .Index(t => t.MaNXB);
            
            CreateTable(
                "dbo.tbl_HocHam",
                c => new
                    {
                        MaHocHam = c.Int(nullable: false, identity: true),
                        HocHam = c.String(nullable: false, maxLength: 50),
                        GhiChu = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.MaHocHam);
            
            CreateTable(
                "dbo.tbl_HocVi",
                c => new
                    {
                        MaHocVi = c.Int(nullable: false, identity: true),
                        HocVi = c.String(nullable: false, maxLength: 50),
                        GhiChu = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.MaHocVi);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.tbl_TacGia", "MaHocVi", "dbo.tbl_HocVi");
            DropForeignKey("dbo.tbl_TacGia", "MaHocHam", "dbo.tbl_HocHam");
            DropForeignKey("dbo.tbl_GiaoTrinh", "MaTacGia", "dbo.tbl_TacGia");
            DropForeignKey("dbo.tbl_SachBan", "MaGiaoTrinh", "dbo.tbl_GiaoTrinh");
            DropForeignKey("dbo.tbl_SachDat", "MaNXB", "dbo.tbl_NhaXuatBan");
            DropForeignKey("dbo.tbl_GiaoTrinh", "MaNXB", "dbo.tbl_NhaXuatBan");
            DropForeignKey("dbo.tbl_SachBan", "MaKhoa", "dbo.tbl_Khoa");
            DropForeignKey("dbo.tbl_MonHoc", "MaKhoa", "dbo.tbl_Khoa");
            DropForeignKey("dbo.tbl_MonHoc", "MaGiaoTrinh", "dbo.tbl_GiaoTrinh");
            DropForeignKey("dbo.tbl_DaoTao", "MaMonHoc", "dbo.tbl_MonHoc");
            DropForeignKey("dbo.tbl_DaoTao", "MaNganh", "dbo.tbl_Nganh");
            DropForeignKey("dbo.tbl_GiaoTrinh_Nam", "MaGiaoTrinh", "dbo.tbl_GiaoTrinh");
            DropForeignKey("dbo.tbl_GiaoTrinh_HeDT", "MaGiaoTrinh", "dbo.tbl_GiaoTrinh");
            DropForeignKey("dbo.tbl_GiaoTrinh_HeDT", "MaHeDaoTao", "dbo.tbl_HeDaoTao");
            DropForeignKey("dbo.tbl_TacGia", "MaChucVu", "dbo.tbl_ChucVu");
            DropForeignKey("dbo.tbl_ChucNang_Quyen", "MaCN", "dbo.tbl_ChucNang");
            DropForeignKey("dbo.tbl_NguoiDung", "MaQuyen", "dbo.tbl_Quyen");
            DropForeignKey("dbo.tbl_ChucNang_Quyen", "MaQuyen", "dbo.tbl_Quyen");
            DropIndex("dbo.tbl_SachDat", new[] { "MaNXB" });
            DropIndex("dbo.tbl_SachBan", new[] { "MaKhoa" });
            DropIndex("dbo.tbl_SachBan", new[] { "MaGiaoTrinh" });
            DropIndex("dbo.tbl_DaoTao", new[] { "MaMonHoc" });
            DropIndex("dbo.tbl_DaoTao", new[] { "MaNganh" });
            DropIndex("dbo.tbl_MonHoc", new[] { "MaGiaoTrinh" });
            DropIndex("dbo.tbl_MonHoc", new[] { "MaKhoa" });
            DropIndex("dbo.tbl_GiaoTrinh_Nam", new[] { "MaGiaoTrinh" });
            DropIndex("dbo.tbl_GiaoTrinh_HeDT", new[] { "MaHeDaoTao" });
            DropIndex("dbo.tbl_GiaoTrinh_HeDT", new[] { "MaGiaoTrinh" });
            DropIndex("dbo.tbl_GiaoTrinh", new[] { "MaNXB" });
            DropIndex("dbo.tbl_GiaoTrinh", new[] { "MaTacGia" });
            DropIndex("dbo.tbl_TacGia", new[] { "MaChucVu" });
            DropIndex("dbo.tbl_TacGia", new[] { "MaHocVi" });
            DropIndex("dbo.tbl_TacGia", new[] { "MaHocHam" });
            DropIndex("dbo.tbl_NguoiDung", new[] { "MaQuyen" });
            DropIndex("dbo.tbl_ChucNang_Quyen", new[] { "MaCN" });
            DropIndex("dbo.tbl_ChucNang_Quyen", new[] { "MaQuyen" });
            DropTable("dbo.tbl_HocVi");
            DropTable("dbo.tbl_HocHam");
            DropTable("dbo.tbl_SachDat");
            DropTable("dbo.tbl_NhaXuatBan");
            DropTable("dbo.tbl_SachBan");
            DropTable("dbo.tbl_Khoa");
            DropTable("dbo.tbl_Nganh");
            DropTable("dbo.tbl_DaoTao");
            DropTable("dbo.tbl_MonHoc");
            DropTable("dbo.tbl_GiaoTrinh_Nam");
            DropTable("dbo.tbl_HeDaoTao");
            DropTable("dbo.tbl_GiaoTrinh_HeDT");
            DropTable("dbo.tbl_GiaoTrinh");
            DropTable("dbo.tbl_TacGia");
            DropTable("dbo.tbl_ChucVu");
            DropTable("dbo.tbl_NguoiDung");
            DropTable("dbo.tbl_Quyen");
            DropTable("dbo.tbl_ChucNang_Quyen");
            DropTable("dbo.tbl_ChucNang");
            DropTable("dbo.sysdiagrams");
        }
    }
}
